var http = require('../http_utils.js');
var util = require('../../util');
const { user } = require('../api.js');
// 用户登录
const url = 'user/'
const login = (param = {}) => {
    var token = wx.getStorageSync('token');
    console.log(token)
    // if (token.length != 0) {
    //     return
    // }
    wx.login({
        success(res) {
            // console.log(res)
            // if (res.code) {
                http.post(url + 'auth', { type: 'wx', js_code: res.code }).then(res => {
                    if(res.code==2000){
                        wx.setStorageSync('token', res.data.token);
                        // wx.switchTab({
                        //     url: "/pages/index/index"
                        // })
                    }else if(res.code==5001){
                        console.log('跳转绑定页面')
                        wx.redirectTo({
                            url: "/pages/bindingAccount/bindingAccount"
                        })
                    }else{

                    }
                })
                .catch(e => {
                    console.log('To' + e)
                })
            // } else {
            //     console.log('登录失败！' + res.errMsg)
            // }
        }
    })
}

const bindwx = (param={}) =>{
    return http.post(url+'bindwx',param);
}

// 心情监测
const mymood = (param={}) =>{
    return http.post(url+'mymood',param);
}
// 心情监测
const information = (param={}) =>{
    return http.get(url+'information',param);
}


module.exports = {
    login,
    mymood,
    information,
    bindwx
}

